package com.ruoyi.quartz.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.quartz.domain.TInventory;
import com.ruoyi.quartz.service.ITInventoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/system/inventory")
public class TInventoryController extends BaseController
{
    private String prefix = "system/inventory";

    @Autowired
    private ITInventoryService tInventoryService;

    @RequiresPermissions("system:inventory:view")
    @GetMapping()
    public String inventory()
    {
        return prefix + "/inventory";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:inventory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TInventory tInventory)
    {
        startPage();
        List<TInventory> list = tInventoryService.selectTInventoryList(tInventory);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:inventory:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TInventory tInventory)
    {
        List<TInventory> list = tInventoryService.selectTInventoryList(tInventory);
        ExcelUtil<TInventory> util = new ExcelUtil<TInventory>(TInventory.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:inventory:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TInventory tInventory)
    {
        return toAjax(tInventoryService.insertTInventory(tInventory));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:inventory:edit")
    @GetMapping("/edit/{inventId}")
    public String edit(@PathVariable("inventId") Long inventId, ModelMap mmap)
    {
        TInventory tInventory = tInventoryService.selectTInventoryByInventId(inventId);
        mmap.put("tInventory", tInventory);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:inventory:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TInventory tInventory)
    {
        return toAjax(tInventoryService.updateTInventory(tInventory));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:inventory:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tInventoryService.deleteTInventoryByInventIds(ids));
    }
}